// let data = { name: "", age: 21 };

// let vm = {};

// let keys = Object.keys(data);
// for (let i in keys) {
//   let key = keys[i]; //"name"，"age"
//   Object.defineProperty(vm, key, {
//     enumerable: true, //可读
//     configurable: false, //可以删除
//     get() {
//       // return vm[key];
//       return data[key]
//     },
//     set(val) {
//       data[key] = val;
//     },
//   });
// }





class Vue {
  $options;
  _data;
  constructor(options) {
    this.$options = options;
    this._data = options.data;
    this.initData();
  }

  initData() {
    // this   ,   this._data
    let keys = Object.keys(this._data);
    for (let i in keys) {
      let key = keys[i];   //  "name","age"
      Object.defineProperty(this,key,{
        enumerable:true,
        configurable:true,
        set(val){
          this._data[key]=val
        },
        get(){
          return this._data[key]
        }
      })
    }
  }
}

let vm = new Vue({
  data: { name: "张三", age: 21 },
});
